﻿using System.Runtime.Versioning;
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Core.Handlers;
using CommunityToolkit.Maui.Views;

namespace CommunityToolkit.Maui;

/// <summary>
/// This class contains CameraView's <see cref="MauiAppBuilder"/> extensions.
/// </summary>
[SupportedOSPlatform("windows10.0.10240.0")]
[SupportedOSPlatform("android21.0")]
[SupportedOSPlatform("ios15.0")]
[SupportedOSPlatform("maccatalyst15.0")]
[SupportedOSPlatform("tizen6.5")]
public static class AppBuilderExtensions
{
	/// <summary>
	/// Initializes the .NET MAUI Community Toolkit CameraView Library
	/// </summary>
	/// <param name="builder"><see cref="MauiAppBuilder"/> generated by <see cref="MauiApp"/>.</param>
	/// <returns><see cref="MauiAppBuilder"/> initialized for <see cref="CameraView"/>.</returns>
	public static MauiAppBuilder UseMauiCommunityToolkitCamera(this MauiAppBuilder builder)
	{
		builder.Services.AddSingleton<ICameraProvider, CameraProvider>();
		builder.ConfigureMauiHandlers(h => h.AddHandler<CameraView, CameraViewHandler>());

		return builder;
	}
}